﻿using Mate.Caching;
using Mate.Db.Model.Info;
using Mate.Db.Model.Merchant;
using Mate.Db.SqlSugar;
using Mate.Dto.Merchant;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;

namespace Mate.Merchant.Service
{
    public class StatisticsDataService : DataService<mp_statistics_data>, IStatisticsDataService
    {
        private readonly ICacheManager _cache;
        public StatisticsDataService(DataClient dataClient, ICacheManager cache) : base(dataClient)
        {
            this._cache = cache;
        }

        /// <summary>
        /// 获取统计数据列表
        /// </summary>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">每页条数</param>
        /// <param name="Key">商户名称</param>
        /// <param name="recordCount">总条数</param>
        /// <returns></returns>
        public IList<StatisticsDataModel> GetStatisticsDataList(int pageIndex, int pageSize, string Key, ref int recordCount)
        {
            return dataClient.Queryable<mp_statistics_data, mp_merchant>((s, m) => new object[]{
                JoinType.Left,s.mechantid==m.id
                })
                .WhereIF(!string.IsNullOrWhiteSpace(Key), (s, m) => m.merchantname.Contains(Key))
                .OrderBy((s, m) => s.id)
                .Select<StatisticsDataModel>("s.*,m.merchantname")
                .ToPageList(pageIndex, pageSize, ref recordCount);
        }
    }
}
